//package com.allenkerr.config;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import javax.annotation.Resource;
//
//import org.springframework.cache.CacheManager;
//import org.springframework.cache.annotation.CachingConfigurerSupport;
//import org.springframework.cache.annotation.EnableCaching;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.cache.DefaultRedisCachePrefix;
//import org.springframework.data.redis.cache.RedisCacheManager;
//import org.springframework.data.redis.cache.RedisCachePrefix;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
//
//import com.allenkerr.constant.Demo13Constants;
//
///**
// * 仅适用于 SpringBoot 1.0
// */
//@Configuration
//@EnableCaching
//public class CacheConfig extends CachingConfigurerSupport {
//
////  @Bean
////  public JedisConnectionFactory redisConnectionFactory() {
////    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
////    // Defaults
////    redisConnectionFactory.setHostName("127.0.0.1");
////    redisConnectionFactory.setPort(6379);
////    return redisConnectionFactory;
////  }
//
////  @Bean
////  public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory cf) {
////    RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
////    redisTemplate.setConnectionFactory(cf);
////    return redisTemplate;
////  }
//
//  @Resource
//  RedisTemplate redisTemplate;
//
//  @Bean
//  public RedisTemplate getRedisTemplate() {
//    StringRedisSerializer stringSerializer = new StringRedisSerializer();
//    redisTemplate.setKeySerializer(stringSerializer);
//    redisTemplate.setHashKeySerializer(stringSerializer);
//
//    GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer();
//    redisTemplate.setValueSerializer(serializer);
//    redisTemplate.setHashValueSerializer(serializer);
//    return redisTemplate;
//  }
//
//  @Bean
//  public CacheManager cacheManager(RedisTemplate redisTemplate) {
//    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
//    // Number of seconds before expiration. Defaults to unlimited (0)
//    cacheManager.setDefaultExpiration(300L);
//
////    RedisCachePrefix redisCachePrefix = new DefaultRedisCachePrefix("all-test:");
////    cacheManager.setCachePrefix(redisCachePrefix);
//    cacheManager.setUsePrefix(true);
//
//    Map<String, Long> expires = new HashMap<>();
//    expires.put(Demo13Constants.REDIS_KEY, 100L);
//    cacheManager.setExpires(expires);
//
//    return cacheManager;
//  }
//}